﻿
//显示
$(function () {
    // 获取当前日期时间
    var now = new Date();
    var hours = ("0" + now.getHours()).slice(-2);
    var minutes = ("0" + now.getMinutes()).slice(-2);
    var seconds = ("0" + now.getSeconds()).slice(-2);
    var serialNumber = "CK" + hours + minutes + seconds;
    console.log(serialNumber)
    $("#storageNumbering").val(serialNumber)
    //采购信息反填
    Procuredfantian()
})
//采购信息反填
function Procuredfantian(){
    layui.use('layer', function () {
        var form = layui.form;
        var stoProid = localStorage["storageprocuredId"] 
        $.ajax({
            url: "/RawMaterial/ProcuredMondel",
            type: "get",
            data: {
                Id: stoProid,
            },
            success: function (data) {
                data = JSON.parse(data);
                $("#detailsNumbering").val(data.data.procuredNumber)
                $("#detailsName").val(data.data.feedstockName)
                $("#detailsNumber").val(data.data.lotNumber)
                $("#detailsNum").val(data.data.feedstockNum)
                var now = new Date(data.data.addTime);
                var year = now.getFullYear()
                var month = ("0" + now.getMonth() + 2).slice(-2);
                var day = ("0" + now.getDate()).slice(-2);
                console.log(year + "-" + month + "-" + day)
                $("#detailsDate").val(year + "-" + month + "-" + day)
            }


        })
    });
}

layui.use(function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        console.log(field);//field.products
        // 显示填写结果，仅作演示用
        //debugger
        $.ajax({
            url: '../Storages/StoragesAdd',
            type: 'post',
            data: { data: JSON.stringify(field), token: localStorage.getItem("token") },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(field);
                console.log(res);
                if (res.data == 1) {
                    layer.alert("添加成功");
                    location.href = '/ProcurementAndStorage/PASshow'
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });
})

